<template>
  <view>
    <!-- 条件编译小组件 -->
    <ifdef></ifdef>
    <navigator open-type="navigate" url="../4-14/4-14"><button type="primary">跳转到4-14测试多监听</button></navigator>
    <MyTabs :tabList="list"></MyTabs>
    <view>
      <view>父组件内的按钮</view>
      <button size="mini" type="primary" @tap="add">父组件列表更改</button>
      <button size="mini" type="primary" @tap="remove">取消父组件监听</button>
      <button size="mini" type="primary" @tap="removeall">取消全部监听</button>
    </view>
    <view>打开控制台查看事件监听</view>
    <view>下面是显示父页面data里的list</view>
    <view v-for="(item, index) in list" :key="index">{{ item.id }} --- {{ item.name }} --- {{ item.isActive }}</view>
  </view>
</template>

<script>
import ifdef from '../../components/ifdef/ifdef.vue';
import MyTabs from '../../components/MyTabs/MyTabs.vue';
export default {
  components: {
    ifdef,
    MyTabs
  },
  data() {
    return {
      list: [
        {
          id: 0,
          name: '要闻',
          isActive: true,
          text:"这是要闻页面的内容。这是要闻页面的内容。这是要闻页面的内容。"
        },
        {
          id: 1,
          name: '推荐',
          isActive: false
        },
        {
          id: 2,
          name: '原创',
          isActive: false
        }
      ]
    };
  },
  methods: {
    tabChange(data) {
      var self = this;
      console.log('父组件获取事件');
      this.list = data;
    },
    remove() {
      uni.$off('tabChange', this.tabChange);
    },
    removeall() {
      uni.$off('tabChange');
    },
    add() {
      this.list = [
        {
          id: 0,
          name: '要闻',
          isActive: true
        },
        {
          id: 1,
          name: '推荐',
          isActive: false
        },
        {
          id: 2,
          name: '原创',
          isActive: false
        },
        {
          id: 3,
          name: '自定义',
          isActive: false
        }
      ];
    }
  },
  onLoad() {
    uni.$on('tabChange', this.tabChange);
  },
  onUnload() {
    uni.$off('tabChange', this.tabChange);
  }
};
</script>

<style lang="less"></style>
